<?php
/**
 * Hostname Rule
 * Validates that a particular value is a valid hostname.
 *
 * @package     Visi
 * @subpackage  Rules
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id$
 */
class Visi_Rule_Hostname extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     */
    protected $_params = array(
        'allowLocalhost' => false,
    );
    
    public function isValid($value) {
    
        if ($this->getParam('allowLocalhost')) {
            if (strtolower($value) == 'localhost') {
                return true;
            }
        }
        return preg_match('/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$/', $value);
    
    }

}
